# 引用.config文件中的配置项内容
CONFIG_PATH = .config
-include $(CONFIG_PATH)

# menuconfig 相关
MCONF_DIR ?= scripts
VPATH += $(MCONF_DIR)
AUTO_CONFIG_FILE ?= scripts/confdata.c
AUTO_CONFIG_TARGET ?= autoconf

LIBFLAG = -lJustDoIt
LIBFLAG += -lsqlite3 
ifeq ($(CONFIG_READLINE_COMPILE), y)
LIBFLAG += -lreadline 
endif

APP_TARGET = just_do_it
CC = gcc
INCLUDE := -include autoconf.h
OBJ = recite.c 
SYS_APP_DIR = /usr/local/bin

.PHONY:clean menuconfig defconfig oldconfig help deb 

$(APP_TARGET): $(OBJ)
	gcc $(INCLUDE)  $^ -o $@ $(LIBFLAG)
	sudo mv $@ $(SYS_APP_DIR) && ls $(SYS_APP_DIR)/$@ -ll

deb:$(OBJ)
	gcc $(INCLUDE)  -L../app $^ -o ../app/$(APP_TARGET) $(LIBFLAG)

menuconfig:
	$(MCONF_DIR)/mconf $(MCONF_DIR)/Kconfig
	$(CC) $(AUTO_CONFIG_FILE) -o $(AUTO_CONFIG_TARGET)
	./$(AUTO_CONFIG_TARGET)

defconfig:
	rm -f *.config
	cp $(MCONF_DIR)/$@  ./.config
	$(CC) $(AUTO_CONFIG_FILE) -o $(AUTO_CONFIG_TARGET)
	./$(AUTO_CONFIG_TARGET)

oldconfig:
	cp .config.old .config
	$(CC) $(AUTO_CONFIG_FILE) -o $(AUTO_CONFIG_TARGET)
	./$(AUTO_CONFIG_TARGET)

help:
	@echo "usage:"
	@echo "       make           		//编译本软件，每次修改配置参数后重新make以生效"
	@echo "       make menuconfig		//个性化配置软件相关参数"
	@echo "       make oldconfig 		//恢复上一次的配置"
	@echo "       make defconfig 		//启用默认配置"

clean:
	sudo rm -f $(SYS_APP_DIR)/$(APP_TARGET)